//
//  VisitorTableViewController.swift
//  Weibo
//
//  Created by 李亚乐 on 15/12/6.
//  Copyright © 2015年 李亚乐. All rights reserved.
//

import UIKit

class VisitorTableViewController: UITableViewController {

    private var logon = UserAccountViewModel.sharedUserAccount.userLogon
    var visitView: VisitorView?
    
    override func loadView() {
        
        logon ? super.loadView() : setupVisitorView()

    }
    
    private func setupVisitorView() {
        
        visitView = VisitorView()
        
        view = visitView
        
        visitView?.registerButton.addTarget(self, action: "visitorViewDidRegister", forControlEvents: UIControlEvents.TouchUpInside)
        visitView?.logonButton.addTarget(self, action: "visitorViewDidLogin", forControlEvents: UIControlEvents.TouchUpInside)
    ///添加事件
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewDidLogin")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: .Plain, target: self, action: "visitorViewDidLogin")
    }
    
}

extension VisitorTableViewController {
    func visitorViewDidRegister() {
        print("注册")
    }
    
    func visitorViewDidLogin() {
        let nav = UINavigationController(rootViewController: OAuthViewController())
        
        presentViewController(nav, animated: true, completion: nil)
    }
}



